//
//  VideoView.m
//  SecretAlbums
//
//  Created by BabyFinancial on 15/7/23.
//  Copyright (c) 2015年 BabyFinancial. All rights reserved.
//

#import "VideoView.h"
#import "SecretAlbumsLogic.h"
#import "Masonry.h"

@implementation VideoView

- (void)setIndex:(NSUInteger)index
{
    _index = index;
    [self displayAtIndex:index];
}

#pragma mark - 私有方法

- (void)displayAtIndex:(NSUInteger)index
{
    if ([self.dataSource respondsToSelector:@selector(mediaAtIndex:)]) {
        Media *media = [self.dataSource mediaAtIndex:index];
        
        [self createImageWithMedia:media];
    }
}

- (void)createImageWithMedia:(Media *)media
{
    self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[SecretAlbumsLogic pathWithMediaType:MediaTypeAspectRatioThumbnail name:media.fileName]]];
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    self.imageView.translatesAutoresizingMaskIntoConstraints = NO;
    
    [self addSubview:self.imageView];
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
}

@end
